<!-- 提交人员 -->
<template>
    <div class="submitPersons clearfix">
        <h4>已提交人员</h4>
        <ul class="clearfix">
            <li v-for="person in submitPersons" @click="checkPerson(submitPersons.indexOf(person), $event)">
                {{ person.userid }}
                <img class="redDot" src="/dist/img/admin/redDot.png" v-if="person.isNew">
            </li>
        </ul>
        <!-- <a @click="downloadChecked()" style="margin-left:2em;">下载选中</a> -->
        <a @click="downloadAll()">下载全部</a>
    </div>
</template>

<style lang="sass">
    .submitPersons{
        .selected{
            background:#e3f2fd;
        }
        li{
            min-width:72px;
            height: 28px;
            text-align: center;
            position: relative;
            float: left;
            padding: 0 1em;
            line-height: 28px;
            cursor:pointer;
            img{
                float: right;
                margin-top:4px;
            }

            &:hover{
                background:#e3f2fd;
            }
        }
        a{
            float: right;
            cursor: pointer;
        }

    }
</style>

<script>
    export default{
        data(){
            return {
                staffArr:[],
            }
        },
        props:['homework', 'submitPersons', 'selfCheckOpen', 'masterCheckOpen' ,'detailOpen', 'submitPersonsOpen'],
        methods:{
            // 选取下载列表
            checkPerson(index,$event){
                // var eventPerson = $event.target;
                // if (eventPerson.className == 'selected') {
                //     eventPerson.className = '';
                // }
                // else {
                //     eventPerson.className = 'selected';
                // }
                // this.staffArr.push(this.submitPersons[index].userid);

                var commentID = this.submitPersons[index].commentID;
                this.$http.post('/admin/work/mas', {'commentID': commentID}).then(function (d) {
                    this.homework['user'] = this.submitPersons[index];
                    this.homework['user']['avatarMsg'] = d.data;
                    this.homework['user']['isNew'] = false;

                    this.masterCheckOpen = true;
                    this.selfCheckOpen = true;
                    this.detailOpen = false;
                    this.submitPersonsOpen = false;
                }, function (err) {
                    alert(err)
                })


            },
            downloadChecked(){
                // 接口传参,获取下载列表
                this.$http.post('/admin/work/masDownload', {
                    'homeworkName': this.homework.homeworkName,
                    'staffArr': this.staffArr
                }).then(function (d) {
                    // 通过插入iframe实现批量下载
                    for (var i = 0; i < d.data.length; i++) {
                        var iframe = document.createElement('iframe');
                        iframe.style.display = 'none';
                        iframe.src = d.data[i];
                        document.body.appendChild(iframe);
                    };
                }, function (err) {
                    alert('err: ' + err.status);
                });
            },
            downloadAll(){
                var length = this.submitPersons.length;
                for (var i = 0; i < length; i++) {
                    var iframe = document.createElement('iframe');
                    iframe.style.display = 'none';
                    iframe.src = this.submitPersons[i].workLink;
                    document.body.appendChild(iframe);
                }
            },
        }
    }
</script>
